package com.zmn.oms.dubbo.impl.zmn.order;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.zmn.base.engineer.dubbo.interfaces.foreign.EngineerListRemoteService;
import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.manager.redis.RedisManager;
import com.zmn.oms.business.interfaces.messageV1.app.MessageSendAppService;
import com.zmn.oms.business.interfaces.servtype.ServItemBService;
import com.zmn.oms.business.interfaces.work.OrderWorkBService;
import com.zmn.oms.business.interfaces.work.OrderWorkListBService;
import com.zmn.oms.common.constant.*;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.dubbo.dto.zmn.order.*;
import com.zmn.oms.dubbo.dto.zmn.serviceitem.OrderServiceItemDRO;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.bo.order.OrderBO;
import com.zmn.oms.model.dto.order.OrderReworkDTO;
import com.zmn.oms.model.dto.order.zmn.ZsNormalNewOrderDTO;
import com.zmn.oms.model.dto.order.zmn.ZsNormalUpdateOrderDTO;
import com.zmn.oms.model.dto.product.OrderProductDTO;
import com.zmn.oms.model.dto.remark.OrderRemarkDetailDTO;
import com.zmn.oms.model.dto.work.masterwork.ModifyQuotationDTO;
import com.zmn.oms.model.dto.work.modify.CheckReworkOrderDTO;
import com.zmn.oms.model.dto.work.modify.must.ZsCancelDTO;
import com.zmn.oms.model.dto.work.modify.other.ZsRemarkDTO;
import com.zmn.oms.model.entity.detail.OrderDetail;
import com.zmn.oms.model.entity.discount.OrderDiscount;
import com.zmn.oms.model.entity.master.OrderMaster;
import com.zmn.oms.model.entity.order.OrderExtend;
import com.zmn.oms.model.entity.product.OrderProduct;
import com.zmn.oms.model.entity.serviceitem.OrderServiceItem;
import com.zmn.oms.model.entity.work.OrderWork;
import com.zmn.base.oms.common.model.es.orderwork.EsOrderWork;
import com.zmn.base.oms.common.model.es.orderwork.EsOrderWorkOperate;
import com.zmn.oms.model.vo.work.ZsNormalUpdateOrderProductVO;
import com.zmn.oms.model.vo.work.ZsNormalUpdateOrderVO;
import com.zmn.oms.model.vo.work.detail.ZsOrderWorkDetailCommentVO;
import com.zmn.oms.model.vo.work.detail.ZsOrderWorkDetailContactVO;
import com.zmn.oms.model.vo.work.detail.ZsOrderWorkDetailVO;
import com.zmn.oms.model.vo.work.detail.ZsOrderWorkDetailWarrantyVO;
import com.zmn.oms.model.vo.work.modify.amount.ZsServiceItemVO;
import com.zmn.oms.model.vo.work.schedule.OrderScheduleVO;
import com.zmn.oms.model.vo.work.schedule.ScheduleDayVo;
import com.zmn.oms.services.interfaces.comment.OrderCommentService;
import com.zmn.oms.services.interfaces.detail.OrderDetailService;
import com.zmn.oms.services.interfaces.discount.OrderDiscountService;
import com.zmn.oms.services.interfaces.master.OrderMasterService;
import com.zmn.oms.services.interfaces.order.OrderExtendService;
import com.zmn.oms.services.interfaces.product.OrderProductService;
import com.zmn.oms.services.interfaces.work.OrderWorkService;
import com.zmn.oms.zmn.business.interfaces.work.ZsOrderWorkBService;
import com.zmn.oms.zmn.business.interfaces.work.ZsOrderWorkQueryBService;
import com.zmn.oms.zmn.business.interfaces.work.ZsOrderWorkScheduleBService;
import com.zmn.oms.zmn.business.interfaces.work.autoflow.WorkFlowContextBService;
import com.zmn.oms.zmn.normal.business.interfaces.discount.ZsNormalOrderDiscountBService;
import com.zmn.oms.zmn.normal.business.interfaces.order.ZsNormalOrderBService;
import com.zmn.oms.zmn.normal.business.interfaces.serviceitem.ZsNormalOrderServiceItemBService;
import com.zmn.oms.zmn.normal.business.interfaces.work.ZsNormalWorkBService;
import io.shardingsphere.api.HintManager;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 类描述：订单 remote service
 *
 * @author liuying
 * @date 2018/11/07 15:10
 */
public abstract class OrderWorkBaseRemoteService extends OrderWorkListBaseRemoteService {
    protected Logger logger = LoggerFactory.getLogger(getClass());

    static final String TAG = "啄木鸟-订单";
    @Reference(version = com.zmn.base.engineer.common.constants.DubboConsts.INTERFACE_VERSION, check = false)
    protected EngineerListRemoteService engineerListRemoteService;
    @Autowired
    protected OrderWorkListBService orderWorkListBService;
    @Autowired
    protected OrderCommentService orderCommentService;
    @Autowired
    protected OrderWorkService orderWorkService;
    @Autowired
    protected OrderWorkBService orderWorkBService;
    @Autowired
    protected ZsNormalWorkBService zsNormalWorkBService;
    @Autowired
    protected ZsNormalOrderBService zsNormalOrderBService;
    @Autowired
    protected OrderProductService orderProductService;
    @Autowired
    protected OrderDiscountService orderDiscountService;
    @Autowired
    protected OrderMasterService orderMasterService;
    @Autowired
    protected OrderDetailService orderDetailService;
    @Autowired
    protected ZsOrderWorkQueryBService orderWorkQueryBService;
    @Autowired
    ZsOrderWorkScheduleBService zsOrderWorkScheduleBService;
    @Autowired
    protected ZsOrderWorkBService zsOrderWorkBService;
    @Autowired
    private WorkFlowContextBService workFlowContextBService;
    @Autowired
    protected ZsNormalOrderServiceItemBService zsNormalOrderServiceItemBService;
    @Autowired
    protected ZsNormalOrderDiscountBService zsNormalOrderDiscountBService;
    @Autowired
    private OrderExtendService orderExtendService;
    @Autowired
    private MessageSendAppService messageSendAppService;
    @Autowired
    private RedisManager redisManager;
    @Autowired
    protected ServItemBService servItemBService;

    /**
     * 返修单检查
     *
     * @param checkReworkOrderDIO
     * @return
     */
    public ResponseDTO checkReworkOrder(CheckReworkOrderDIO checkReworkOrderDIO) {
        CheckReworkOrderDTO checkReworkOrderDTO = BeanMapper.map(checkReworkOrderDIO, CheckReworkOrderDTO.class);
        try {
            OrderReworkDTO orderReworkDTO = zsNormalOrderBService.checkReworkId(checkReworkOrderDTO);
            CheckReworkOrderDRO orderReworkDRO = BeanMapper.map(orderReworkDTO, CheckReworkOrderDRO.class);
            return ResponseDTO.success(orderReworkDRO);
        } catch (OmsBaseException e) {
            return ResponseDTO.fail(e.getMessage());
        }
    }

    /**
     * 获取订单详情
     *
     * @param orderId
     * @return
     */
    public ResponseDTO<OrderDetailDRO> findOrderDetail(Long orderId) {

        Objects.requireNonNull(orderId);

        logger.info("[{}] 商家渠道订单查询：{}", TAG, "orderId:" + orderId);

        OrderDetailDRO orderDetailDRO = new OrderDetailDRO();

        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.setMasterRouteOnly();

            ZsOrderWorkDetailVO orderWorkDetail = orderWorkQueryBService.findOrderWorkDetail(orderId, orderId);

            BeanMapper.copy(orderWorkDetail, orderDetailDRO);
            orderDetailDRO.setWorkId(orderId);
            orderDetailDRO.setOrderId(orderId);

            // 联系信息
            ZsOrderWorkDetailContactVO contactVO = orderWorkDetail.getContactVO();
            if (contactVO != null) {
                orderDetailDRO.setContact(BeanMapper.map(contactVO, OrderContactDRO.class));
            }

            //保修信息
            ZsOrderWorkDetailWarrantyVO warrantyVO = orderWorkDetail.getWarranty();
            if (warrantyVO != null) {
                orderDetailDRO.setWarranty(BeanMapper.map(warrantyVO, OrderDetailWarrantyDRO.class));
            }

            // 评价
            ZsOrderWorkDetailCommentVO commentVO = orderWorkDetail.getUserCommentVO();
            if (commentVO != null) {
                orderDetailDRO.setComment(BeanMapper.map(commentVO, OrderCommentDRO.class));
            }
        }

        return ResponseDTO.success(orderDetailDRO, GlobalConsts.SUCCESS_MSG);
    }

    /**
     * 获取订单
     *
     * @param orderId
     * @return
     */
    public ResponseDTO<OrderDRO> getOrderById(Long orderId, Long workId) {
        if (NumberUtil.isNullOrZero(orderId) || NumberUtil.isNullOrZero(workId)) {
            return ResponseDTO.fail("orderId和workId不能为空");
        }

        try {
            OrderWork orderWork = orderWorkService.findOrderWorkByKeySrcMaster(orderId, workId);
            if (orderWork == null) {
                return ResponseDTO.fail("订单不存在");
            }

            OrderDRO orderDRO = this.getOrderDROByDb(orderWork);
            logger.debug("[{}] getOrderById：{}", TAG, orderDRO);
            return ResponseDTO.success(orderDRO, DubboConsts.OK);
        } catch (Exception e) {
            logger.error("[{}] orderId={},workId={} 获取订单错误：{}", TAG, orderId, workId, e);
            return ResponseDTO.fail(e.getMessage());
        }
    }

    /**
     * 获取订单
     *
     * @param orderId
     * @return
     */
    public ResponseDTO<OrderDRO> getOrderByIdSrcSlave(Long orderId, Long workId) {
        try {
            OrderWork orderWork = orderWorkService.findOrderWorkByKey(orderId, workId);
            if (orderWork == null) {
                return ResponseDTO.fail("订单不存在");
            }

            OrderDRO orderDRO = this.getOrderDROByDbSrcSlave(orderWork);
            logger.debug("[{}] getOrderById：{}", TAG, orderDRO);
            return ResponseDTO.success(orderDRO, DubboConsts.OK);
        } catch (Exception e) {
            logger.error("[{}] orderId={},workId={} 获取订单错误：{}", TAG, orderId, workId, e);
            return ResponseDTO.fail(e.getMessage());
        }
    }

    /**
     * 取消订单
     *
     * @param cancelOrderDIO
     * @return
     */
    public ResponseDTO cancelOrder(CancelOrderDIO cancelOrderDIO) {
        try {
            ZsCancelDTO zsCancelDTO = new ZsCancelDTO();
            zsCancelDTO.setOrderId(cancelOrderDIO.getOrderId());
            zsCancelDTO.setWorkId(cancelOrderDIO.getWorkId());
            zsCancelDTO.setContent(cancelOrderDIO.getRemark());
            if (Objects.nonNull(cancelOrderDIO.getReasonMap()) && cancelOrderDIO.getReasonMap().size() > 0) {
                List<OrderRemarkDetailDTO> detailDTOList = Lists.newArrayList();
                cancelOrderDIO.getReasonMap().forEach((k, v) -> {
                    OrderRemarkDetailDTO dto = new OrderRemarkDetailDTO();
                    dto.setMapId(k);
                    dto.setMapName(v);
                    detailDTOList.add(dto);
                });
                zsCancelDTO.setDetailDTOList(detailDTOList);

            }
            // 操作人信息
            zsCancelDTO.setOperator(Optional.ofNullable(cancelOrderDIO.getOperator()).orElse(cancelOrderDIO.getUserName()));
            zsCancelDTO.setOperatorId(Optional.ofNullable(cancelOrderDIO.getOrderId()).orElse(cancelOrderDIO.getUserId()));
            zsCancelDTO.setOperatorType(Optional.ofNullable(cancelOrderDIO.getOperatorType()).orElse(GlobalConsts.OPERATE_USER_TYPE_FACTORY));

            zsNormalWorkBService.saveCancel(zsCancelDTO);
            return ResponseDTO.success();
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseDTO.fail(e.getMessage());
        }
    }

    /**
     * 修改订单
     *
     * @param updateOrderDTO
     * @return
     */
    public ResponseDTO<NewOrderDRO> updateOrder(ZsNormalUpdateOrderDTO updateOrderDTO) {
        try {
            zsNormalOrderBService.updateOrder(updateOrderDTO);
            return ResponseDTO.success();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("[{}] 订单保存错误：{}", TAG, e);
            return ResponseDTO.fail(e.getMessage());
        }
    }

    /**
     * 新增普通订单
     *
     * @param newOrderDTO
     * @return
     */
    public ResponseDTO<NewOrderDRO> addOrder(ZsNormalNewOrderDTO newOrderDTO) {
        try {
            // 返修单处理
            if (newOrderDTO.getReworkId() != null && newOrderDTO.getPlatWork() == null) {
                OrderWork reworkOrderWork = orderWorkService.findOrderWorkByKey(newOrderDTO.getReworkId(), newOrderDTO.getReworkId());
                if (reworkOrderWork == null) {
                    throw new OmsBaseException("返修单号不能为空");
                }
                // 返修单只能在新单上创建
                if (!Objects.equals(OrderConsts.ORDER_TYPE_NEW, reworkOrderWork.getType())) {
                    throw new OmsBaseException("只能在新单上创建返修单");
                }

                newOrderDTO.setPlat(Optional.ofNullable(newOrderDTO.getPlat()).orElse(reworkOrderWork.getPlat()));
                newOrderDTO.setPlatWork(reworkOrderWork.getPlatWork());
                newOrderDTO.setSourceChannelId(Optional.ofNullable(newOrderDTO.getSourceChannelId()).orElse(reworkOrderWork.getChannelId()));
                newOrderDTO.setOrderServiceItemList(null);
                newOrderDTO.setTest(reworkOrderWork.getTest());
            }

            // 计价器订单，只支持一个产品
            if (servItemBService.isQuotationType(newOrderDTO.getServItemType())) {
                List<OrderProductDTO> products = newOrderDTO.getOrderProductList();
                if (products.size() > 1 || Optional.ofNullable(products.get(0).getNumber()).orElse(1) > 1) {
                    throw new OmsBaseException("计价器订单只支持一个产品");
                }
            }

            // 返修单若是微信公众号来的返修单，重新设置渠道--临时处理
            if (Objects.equals(newOrderDTO.getType(), OrderConsts.ORDER_TYPE_REWORK)) {
                // newOrderDTO.setChannelId(ChannelConsts.CHANNEL_ID_WECHAR_GZH);
                newOrderDTO.setChannelId(ChannelConsts.getReworkChannelId(newOrderDTO.getPlat()));
            }

            // 非服务商工单，新增不需要公司信息
            if (!Objects.equals(GlobalConsts.OPERATE_USER_TYPE_SERVICEPROVIDER, newOrderDTO.getOperatorType())) {
                newOrderDTO.setCompanyId(null);
                newOrderDTO.setManageCompanyId(null);
            }
            {// 特殊处理 2021.08.17 by lhl
                /*
                 * 当渠道ID及产品ID如下，默认服务平台调整为：言而有信
                 *  渠道ID：40001，渠道名称：啄木鸟家庭维修小程序-微信-小程序
                 *  产品ID：13128 ，产品名称：智能锁（雅致银）售卖；
                 *  产品ID：13130 ，产品名称：智能锁（古铜色）售卖
                 */
                if (Objects.equals(newOrderDTO.getChannelId(), 40001)) {
                    Optional.ofNullable(newOrderDTO.getOrderProductList())
                            .map(list -> list.get(0))
                            .map(product -> NumberUtil.isNotNullOrZero(product.getShowProductId())
                                    ? product.getShowProductId()
                                    : product.getProductId()
                            )
                            .filter(productId -> (13128 == productId.intValue() || 13130 == productId.intValue()))
                            .ifPresent(productId -> newOrderDTO.setPlatWork(GlobalConsts.PLAT_MARK_YEYX));
                }
            }

            OrderBO orderBO = zsNormalOrderBService.insertOrder(newOrderDTO);

            NewOrderDRO newOrderDRO = new NewOrderDRO();
            newOrderDRO.setWorkId(orderBO.getOrderWork().getWorkId());
            newOrderDRO.setOrderId(orderBO.getOrderWork().getOrderId());
            newOrderDRO.setUserId(orderBO.getOrderWork().getUserId());
            newOrderDRO.setOriginalAmount(orderBO.getOrderWork().getOriginalAmount());
            logger.info("[{}] 添加订单返回：{}", TAG, newOrderDRO);

            OrderWork orderWork = orderBO.getOrderWork();

            // 新增人工派单备注（更换工程师（用户希望指派非原单工程师维修））
            if (Objects.equals(GlobalConsts.NO, newOrderDTO.getAutoDistribute())) {
                ZsRemarkDTO dto = BeanMapper.map(newOrderDTO, ZsRemarkDTO.class);
                dto.setRemark("更换工程师（用户希望指派非原单工程师维修）");
                dto.setOrderId(orderWork.getOrderId());
                dto.setWorkId(orderWork.getWorkId());
                zsNormalOrderBService.saveWorkRemark(dto);
            }

            // 百度消息条件判断
            if (StringUtils.isNotBlank(newOrderDTO.getSceneId())) {
                // 由于单子不知道什么时候能完成，固在redis保存设置失效时间，默认为90天，工单取消和完成后自动删除
                String redisKey = String.format(RedisKeyConsts.BAIDU_SCENEIDS_REDIS_KEY, String.valueOf(orderWork.getWorkId()));
                redisManager.setex(redisKey, newOrderDTO.getSceneId(), 3600 * 24 * 90);
            }

            // 计价器小程序下单，初始化为确认报价
            if (Objects.equals(GlobalConsts.NO, newOrderDTO.getNegotiatedPriceFlag())) {
                // 用户最终确认报价，进行保存确认标示
                String redisKey = String.format(RedisKeyConsts.USER_HAVE_CONFIRM_QUOTATION_KEY, String.valueOf(orderWork.getOrderId()));
                if (!redisManager.exists(redisKey)) {
                    // 由于单子不知道什么时候能完成，固在redis保存设置失效时间，默认为3个月，工单取消和完成后自动删除
                    redisManager.setex(redisKey, DateUtil.getNowFormatted(), 3600 * 24 * 90);
                }
            }

            // 工单自动流转
            workFlowContextBService.asyncAutoFlow(orderWork.getOrderId(), orderWork.getWorkId());

            return ResponseDTO.success(newOrderDRO, "OK");
        } catch (OmsBaseException e) {
            logger.error(String.format("%s订单保存错误:%s", TAG, e.getMessage()), e);
            logger.error("[{}] 订单保存错误，错误码【{}】", TAG, e.getCode());
            if (Objects.nonNull(e.getCode()) && e.getCode() > OmsErrorCodeConsts.MIN_CODE) {
                return ResponseDTO.fromErrorCodeTable(e.getCode());
            }
            return ResponseDTO.fail(e.getCode(), e.getMessage());
        }  catch (Exception e) {
            logger.error(String.format("%s订单保存错误:%s", TAG, e.getMessage()), e);
            logger.error("[{}] 订单保存错误：{}", TAG, e);
            return ResponseDTO.fail(e.getMessage());
        }
    }

    /**
     * 修改产品/故障项
     *
     * @param modifyQuotationDTO
     * @return
     */
    public ResponseDTO<Boolean> updateOrderProduct(ModifyQuotationDTO modifyQuotationDTO) {
        logger.debug("start更新产品----->[{}]", JSON.toJSONString(modifyQuotationDTO));
        try {
            zsOrderWorkBService.updateOrderQuotation(modifyQuotationDTO);

            OrderWork orderWork = orderWorkService.findOrderWorkByKey(modifyQuotationDTO.getOrderId(), modifyQuotationDTO.getWorkId());

            Integer masterId = orderWork.getMasterId();

            // 为2属于议价 不进行下面处理
            if (Objects.equals(modifyQuotationDTO.getNegotiatedPriceFlag(), GlobalConsts.YES)) {
                return ResponseDTO.success(true, "OK");
            }

            // 用户最终确认报价，进行保存确认标示
            String redisKey = String.format(RedisKeyConsts.USER_HAVE_CONFIRM_QUOTATION_KEY, String.valueOf(modifyQuotationDTO.getOrderId()));
            if (!redisManager.exists(redisKey)) {
                // 由于单子不知道什么时候能完成，固在redis保存设置失效时间，默认为3个月，工单取消和完成后自动删除
                redisManager.setex(redisKey, DateUtil.getNowFormatted(), 3600 * 24 * 90);
            }

            // 给工程师发送消息，只有最终报价才推送消息，议价不进行推送消息
            if (Objects.equals(modifyQuotationDTO.getQuotationType(), GlobalConsts.OPERATE_USER_TYPE_USER) && masterId != null && modifyQuotationDTO.getQuotationId() != null) {
                // 计价器故障项报价push推送
                Map<String, Object> params = Maps.newHashMap();
                params.put("order_id", String.valueOf(orderWork.getOrderId()));
                params.put("work_id", String.valueOf(orderWork.getWorkId()));
                params.put("quotation_id", String.valueOf(modifyQuotationDTO.getQuotationId()));
                messageSendAppService.pushAppMessageInfo(MessageRuleIdConsts.PUSH_MSG_RULEID_LDD_BONUS, JSON.toJSONString(params),orderWork);
            }
            return ResponseDTO.success(true, "OK");
        } catch (OmsBaseException e) {
            logger.error(e.getMessage(), e);
            logger.error("[{}] 修改产品/故障项错误：{}", TAG, e);
            return ResponseDTO.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            logger.error("[{}] 修改产品/故障项错误：{}", TAG, e);
            return ResponseDTO.fail(e.getMessage());
        }
    }

    /**
     * 获取预约时间
     *
     * @return
     */
    public ResponseDTO<List<OrderScheduleDayDRO>> getScheduleDayList() {
        try {
            List<ScheduleDayVo> scheduleDayList = zsOrderWorkScheduleBService.getScheduleDayList();
            List<OrderScheduleDayDRO> list = BeanMapper.mapList(scheduleDayList, OrderScheduleDayDRO.class);
            return ResponseDTO.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("[{}] 获取预约时间错误：{}", TAG, e);
            return ResponseDTO.fail(e.getMessage());
        }

    }

    /**
     * 获取预约时间
     *
     * @param scheDate
     * @return
     */
    public ResponseDTO<OrderScheduleTimeDRO> getScheduleTimes(String scheDate) {
        try {
            Objects.requireNonNull(scheDate, "预约日期不能为空");
            OrderScheduleVO scheduleTimes = zsOrderWorkScheduleBService.getScheduleTimes(scheDate, null);
            OrderScheduleTimeDRO scheduleTimeDRO = BeanMapper.map(scheduleTimes, OrderScheduleTimeDRO.class);
            return ResponseDTO.success(scheduleTimeDRO);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("[{}] 获取预约时间错误：{}", TAG, e);
            return ResponseDTO.fail(e.getMessage());
        }
    }

    /**
     * 订单转化
     *
     * @param orderWork
     * @return
     */
    protected OrderDRO getOrderDROByDb(OrderWork orderWork) {
        OrderDRO orderDRO = new OrderDRO();

        OrderDetail orderDetail = orderDetailService.findOrderDetailByKeySrcMaster(orderWork.getOrderId());

        orderDRO.setPlat(orderWork.getPlat());
        orderDRO.setPlatWork(orderWork.getPlatWork());
        orderDRO.setOrderId(orderWork.getOrderId());
        orderDRO.setWorkId(orderWork.getWorkId());
        orderDRO.setType(orderWork.getType());
        orderDRO.setFinalPrice(orderWork.getFinalPrice());
        orderDRO.setReworkId(orderWork.getReworkId());
        orderDRO.setDutyTime(orderWork.getDutyTime());
        orderDRO.setProvinceId(orderDetail.getProvinceId());
        orderDRO.setProvinceName(orderDetail.getProvinceName());
        orderDRO.setCountryId(orderDetail.getCountyId());
        orderDRO.setCountryName(orderDetail.getCountyName());
        orderDRO.setStreet(orderDetail.getStreet());
        orderDRO.setRemark(orderDetail.getRemark());
        orderDRO.setLatitude(orderDetail.getLatitude());
        orderDRO.setLongitude(orderDetail.getLongitude());
        orderDRO.setAddress(orderDetail.getAddress());
        orderDRO.setTest(orderWork.getTest());

        orderDRO.setOrgOneId(orderWork.getOrgOneId());
        orderDRO.setOrgTwoId(orderWork.getOrgTwoId());
        orderDRO.setOrgThreeId(orderWork.getOrgThreeId());
        orderDRO.setOrgFourId(orderWork.getOrgFourId());
        orderDRO.setChannelOneId(orderWork.getChannelOneId());
        orderDRO.setChannelTwoId(orderWork.getChannelTwoId());
        orderDRO.setBizLine(orderWork.getBizLine());
        orderDRO.setServProductGroupId(orderWork.getServProductGroupId());
        orderDRO.setServProductGroupName(orderWork.getServProductGroupName());
        orderDRO.setMember(orderWork.getMember());

        orderDRO.setDiscountAmount(orderWork.getDiscountAmount());
        orderDRO.setCompleteTime(orderWork.getCompleteTime());
        orderDRO.setOriginalAmount(orderWork.getOriginalAmount());
        orderDRO.setPayStatus(orderWork.getPayStatus());
        orderDRO.setRefundTargetWorkId(orderWork.getRefundTargetWorkId());
        orderDRO.setCityId(orderWork.getCityId());
        orderDRO.setCityName(orderDetail.getCityName());
        orderDRO.setCategOneId(orderWork.getCategOneId());
        orderDRO.setCategId(orderWork.getCategId());
        orderDRO.setChannelId(orderWork.getChannelId());
        orderDRO.setChannelName(orderWork.getChannelName());
        orderDRO.setCompantyId(orderWork.getCompanyId());
        orderDRO.setCompanyId(orderWork.getCompanyId());
        orderDRO.setCompanyName(orderWork.getCompanyName());
        orderDRO.setManageCompanyId(orderWork.getManageCompanyId());
        orderDRO.setManageCompanyame(orderWork.getManageCompanyName());
        orderDRO.setGridCompanyId(orderDetail.getGridCompanyId());
        orderDRO.setGridCompanyName(orderDetail.getGridCompanyName());
        orderDRO.setGridManageCompanyId(orderDetail.getGridManageCompanyId());
        orderDRO.setGridManageCompanyName(orderDetail.getGridManageCompanyName());
        orderDRO.setUserId(orderWork.getUserId());
        orderDRO.setServCategId(orderWork.getServCategId());
        orderDRO.setUserGender(orderDetail.getGender());
        orderDRO.setUserName(orderDetail.getUserName());
        orderDRO.setUserPhone(orderDetail.getTelephone());
        orderDRO.setStatus(orderWork.getStatus());
        orderDRO.setResultStatus(orderWork.getResultStatus());
        orderDRO.setUserPhoneTwo(orderDetail.getTelephone2());
        orderDRO.setUserPhoneThree(orderDetail.getTelephone3());
        orderDRO.setReciverId(orderWork.getReceiverId());
        orderDRO.setDistributeId(orderWork.getDistributerId());
        orderDRO.setTotalAmount(orderWork.getTotalAmount());
        orderDRO.setBizMode(orderWork.getBizMode());
        orderDRO.setBizModeSource(orderWork.getBizModeSource());
        orderDRO.setBizType(orderWork.getBizType());
        orderDRO.setMasterId(orderWork.getMasterId());
        orderDRO.setMasterName(orderWork.getMasterName());
        orderDRO.setCategOneId(orderWork.getCategOneId());
        orderDRO.setShowCategOneId(orderWork.getShowCategOneId());
        orderDRO.setShowCategId(orderWork.getShowCategId());
        orderDRO.setDistributeTime(orderWork.getDistributeTime());
        orderDRO.setServItemType(orderWork.getServItemType());
        orderDRO.setServCategName(orderDetail.getServCategName());
        orderDRO.setCreateTime(orderWork.getCreateTime());
        // 工单工程师
        List<OrderMaster> orderMasterList = orderMasterService.listMasterByOrderIdList(Lists.newArrayList(orderWork.getOrderId()));
        if (!CollectionUtils.isEmpty(orderMasterList)) {
            Optional<OrderMaster> orderMasterOptional = orderMasterList.stream().filter(e -> Objects.equals(e.getMasterId(), orderWork.getMasterId())).findFirst();
            if (orderMasterOptional.isPresent()) {
                orderDRO.setMasterPhone(orderMasterOptional.get().getMasterPhone());
            }
            List<OrderMaster> slaveMasterList = orderMasterList.stream().filter(e -> !Objects.equals(e.getMasterId(), orderWork.getMasterId())).collect(Collectors.toList());
            if (CollectionUtil.isNotNullOrEmpty(slaveMasterList)) {
                List<OrderMasterDRO> masterList = Lists.newArrayListWithCapacity(slaveMasterList.size());
                slaveMasterList.forEach(orderMaster -> {
                    OrderMasterDRO masterDRO = new OrderMasterDRO();
                    masterDRO.setMasterId(orderMaster.getMasterId());
                    masterDRO.setMasterName(orderMaster.getMasterName());
                    masterList.add(masterDRO);
                });
                orderDRO.setMasterList(masterList);
            }
        }

        //师傅相片
        OrderExtend orderExtend = orderExtendService.findOrderExtendByOrderId(orderWork.getOrderId());
        if (Objects.nonNull(orderExtend)) {
            orderDRO.setMasterSrc(orderExtend.getMasterSrc());
            orderDRO.setDifficultRatioId(orderExtend.getDifficultRatioId());
        }

        // 订单产品
        List<OrderProduct> orderProductList = orderProductService.listOrderProductByOrderIdSrcMaster(orderWork.getOrderId());
        if (!CollectionUtils.isEmpty(orderProductList)) {
            Optional<OrderProduct> orderProductOptional = orderProductList.stream().filter(e -> Objects.equals(e.getProductId(), orderWork.getProductId())).findFirst();
            if (orderProductOptional.isPresent()) {
                orderDRO.setCategOneName(orderProductOptional.get().getCategOneName());
                orderDRO.setShowServCategName(orderProductOptional.get().getShowCategName());
                orderDRO.setShowCategOneName(orderProductOptional.get().getShowCategOneName());
                orderDRO.setShowCategName(orderProductOptional.get().getShowCategName());
            }

            List<OrderProductDRO> orderProductDROList = BeanMapper.mapList(orderProductList, OrderProductDRO.class);
            orderDRO.setProductList(orderProductDROList);
        }

        // 服务项信息
        try {
            List<ZsServiceItemVO> serviceItemVos = zsNormalOrderServiceItemBService.findServiceItemVo(orderWork.getOrderId(), orderWork.getWorkId());
            if (!CollectionUtils.isEmpty(serviceItemVos)) {
                List<OrderServiceItem> orderServiceItems = new LinkedList<>();
                for (ZsServiceItemVO obj : serviceItemVos) {
                    if (!CollectionUtils.isEmpty(obj.getServiceItemList())) {
                        orderServiceItems.addAll(obj.getServiceItemList());
                    }
                }
                List<OrderServiceItemDRO> orerServiceItemDRO = BeanMapper.mapList(orderServiceItems, OrderServiceItemDRO.class);
                orderDRO.setOrderServiceItemList(orerServiceItemDRO);
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }

        // 优惠信息
        List<OrderDiscount> discountList = orderDiscountService.listByOrderId(orderWork.getOrderId());
        orderDRO.setOrderDiscountList(BeanMapper.mapList(discountList, OrderDetailDiscountDRO.class));

        orderDRO.setProductInfo(orderDetail.getProductInfo());
        orderDRO.setMasterSupervisorId(orderWork.getMasterSupervisorId());

        return orderDRO;
    }

    /**
     * 订单转化
     *
     * @param orderWork
     * @return
     */
    protected OrderDRO getOrderDROByDbSrcSlave(OrderWork orderWork) {
        OrderDRO orderDRO = new OrderDRO();

        OrderDetail orderDetail = orderDetailService.findOrderDetailByKey(orderWork.getOrderId());

        orderDRO.setPlat(orderWork.getPlat());
        orderDRO.setPlatWork(orderWork.getPlatWork());
        orderDRO.setOrderId(orderWork.getOrderId());
        orderDRO.setWorkId(orderWork.getWorkId());
        orderDRO.setType(orderWork.getType());
        orderDRO.setReworkId(orderWork.getReworkId());
        orderDRO.setDutyTime(orderWork.getDutyTime());
        orderDRO.setProvinceId(orderDetail.getProvinceId());
        orderDRO.setProvinceName(orderDetail.getProvinceName());
        orderDRO.setCountryId(orderDetail.getCountyId());
        orderDRO.setCountryName(orderDetail.getCountyName());
        orderDRO.setStreet(orderDetail.getStreet());
        orderDRO.setRemark(orderDetail.getRemark());
        orderDRO.setLatitude(orderDetail.getLatitude());
        orderDRO.setLongitude(orderDetail.getLongitude());
        orderDRO.setAddress(orderDetail.getAddress());
        orderDRO.setTest(orderWork.getTest());

        orderDRO.setConfirmTime(orderWork.getConfirmTime());
        orderDRO.setContactTime(orderWork.getContactTime());
        orderDRO.setVisitTime(orderWork.getVisitTime());
        orderDRO.setTakeTime(orderWork.getTakeTime());

        orderDRO.setOrgOneId(orderWork.getOrgOneId());
        orderDRO.setOrgTwoId(orderWork.getOrgTwoId());
        orderDRO.setOrgThreeId(orderWork.getOrgThreeId());
        orderDRO.setOrgFourId(orderWork.getOrgFourId());
        orderDRO.setChannelOneId(orderWork.getChannelOneId());
        orderDRO.setChannelTwoId(orderWork.getChannelTwoId());
        orderDRO.setBizLine(orderWork.getBizLine());
        orderDRO.setServProductGroupId(orderWork.getServProductGroupId());
        orderDRO.setServProductGroupName(orderWork.getServProductGroupName());
        orderDRO.setCategOneId(orderWork.getCategOneId());
        orderDRO.setCategId(orderWork.getCategId());
        orderDRO.setMember(orderWork.getMember());

        orderDRO.setDiscountAmount(orderWork.getDiscountAmount());
        orderDRO.setCompleteTime(orderWork.getCompleteTime());
        orderDRO.setOriginalAmount(orderWork.getOriginalAmount());
        orderDRO.setPayStatus(orderWork.getPayStatus());
        orderDRO.setRefundTargetWorkId(orderWork.getRefundTargetWorkId());
        orderDRO.setCityId(orderWork.getCityId());
        orderDRO.setCityName(orderDetail.getCityName());
        orderDRO.setCategOneId(orderWork.getCategOneId());
        orderDRO.setCategId(orderWork.getCategId());
        orderDRO.setChannelId(orderWork.getChannelId());
        orderDRO.setChannelName(orderWork.getChannelName());
        orderDRO.setCompantyId(orderWork.getCompanyId());
        orderDRO.setCompanyId(orderWork.getCompanyId());
        orderDRO.setCompanyName(orderWork.getCompanyName());
        orderDRO.setManageCompanyId(orderWork.getManageCompanyId());
        orderDRO.setManageCompanyame(orderWork.getManageCompanyName());
        orderDRO.setGridCompanyId(orderDetail.getGridCompanyId());
        orderDRO.setGridCompanyName(orderDetail.getGridCompanyName());
        orderDRO.setGridManageCompanyId(orderDetail.getGridManageCompanyId());
        orderDRO.setGridManageCompanyName(orderDetail.getGridManageCompanyName());
        orderDRO.setUserId(orderWork.getUserId());
        orderDRO.setServCategId(orderWork.getServCategId());
        orderDRO.setUserGender(orderDetail.getGender());
        orderDRO.setUserName(orderDetail.getUserName());
        orderDRO.setUserPhone(orderDetail.getTelephone());
        orderDRO.setStatus(orderWork.getStatus());
        orderDRO.setResultStatus(orderWork.getResultStatus());
        orderDRO.setUserPhoneTwo(orderDetail.getTelephone2());
        orderDRO.setUserPhoneThree(orderDetail.getTelephone3());
        orderDRO.setReciverId(orderWork.getReceiverId());
        orderDRO.setDistributeId(orderWork.getDistributerId());
        orderDRO.setTotalAmount(orderWork.getTotalAmount());
        orderDRO.setBizMode(orderWork.getBizMode());
        orderDRO.setBizModeSource(orderWork.getBizModeSource());
        orderDRO.setBizType(orderWork.getBizType());
        orderDRO.setMasterId(orderWork.getMasterId());
        orderDRO.setMasterName(orderWork.getMasterName());
        orderDRO.setCategOneId(orderWork.getCategOneId());
        orderDRO.setShowCategOneId(orderWork.getShowCategOneId());
        orderDRO.setShowCategId(orderWork.getShowCategId());
        orderDRO.setDistributeTime(orderWork.getDistributeTime());
        orderDRO.setServItemType(orderWork.getServItemType());
        orderDRO.setServCategName(orderDetail.getServCategName());
        orderDRO.setCreateTime(orderWork.getCreateTime());
        // 工单工程师
        List<OrderMaster> orderMasterList = orderMasterService.listMasterByWorkId(orderWork.getOrderId(), orderWork.getWorkId());
        if (!CollectionUtils.isEmpty(orderMasterList)) {
            Optional<OrderMaster> orderMasterOptional = orderMasterList.stream().filter(e -> Objects.equals(e.getMasterId(), orderWork.getMasterId())).findFirst();
            if (orderMasterOptional.isPresent()) {
                orderDRO.setMasterPhone(orderMasterOptional.get().getMasterPhone());
            }
            List<OrderMaster> slaveMasterList = orderMasterList.stream().filter(e -> !Objects.equals(e.getMasterId(), orderWork.getMasterId())).collect(Collectors.toList());
            if (CollectionUtil.isNotNullOrEmpty(slaveMasterList)) {
                List<OrderMasterDRO> masterList = Lists.newArrayListWithCapacity(slaveMasterList.size());
                slaveMasterList.forEach(orderMaster -> {
                    OrderMasterDRO masterDRO = new OrderMasterDRO();
                    masterDRO.setMasterId(orderMaster.getMasterId());
                    masterDRO.setMasterName(orderMaster.getMasterName());
                    masterList.add(masterDRO);
                });
                orderDRO.setMasterList(masterList);
            }
        }

        //师傅相片
        OrderExtend orderExtend = orderExtendService.findOrderExtendByOrderId(orderWork.getOrderId());
        if (Objects.nonNull(orderExtend)) {
            orderDRO.setMasterSrc(orderExtend.getMasterSrc());
            orderDRO.setDifficultRatioId(orderExtend.getDifficultRatioId());
        }

        // 订单产品
        List<OrderProduct> orderProductList = orderProductService.listOrderProductByOrderId(orderWork.getOrderId());
        if (!CollectionUtils.isEmpty(orderProductList)) {
            Optional<OrderProduct> orderProductOptional = orderProductList.stream().filter(e -> Objects.equals(e.getProductId(), orderWork.getProductId())).findFirst();
            if (orderProductOptional.isPresent()) {
                orderDRO.setCategOneName(orderProductOptional.get().getCategOneName());
                orderDRO.setShowServCategName(orderProductOptional.get().getShowCategName());
                orderDRO.setShowCategOneName(orderProductOptional.get().getShowCategOneName());
                orderDRO.setShowCategName(orderProductOptional.get().getShowCategName());
            }

            List<OrderProductDRO> orderProductDROList = BeanMapper.mapList(orderProductList, OrderProductDRO.class);
            orderDRO.setProductList(orderProductDROList);
        }

        // 服务项信息
        try {
            List<ZsServiceItemVO> serviceItemVos = zsNormalOrderServiceItemBService.findServiceItemVo(orderWork.getOrderId(), orderWork.getWorkId());
            if (!CollectionUtils.isEmpty(serviceItemVos)) {
                List<OrderServiceItem> orderServiceItems = new LinkedList<>();
                for (ZsServiceItemVO obj : serviceItemVos) {
                    if (!CollectionUtils.isEmpty(obj.getServiceItemList())) {
                        orderServiceItems.addAll(obj.getServiceItemList());
                    }
                }
                List<OrderServiceItemDRO> orerServiceItemDRO = BeanMapper.mapList(orderServiceItems, OrderServiceItemDRO.class);
                orderDRO.setOrderServiceItemList(orerServiceItemDRO);
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }

        // 优惠信息
        List<OrderDiscount> discountList = orderDiscountService.listByOrderId(orderWork.getOrderId());
        orderDRO.setOrderDiscountList(BeanMapper.mapList(discountList, OrderDetailDiscountDRO.class));

        return orderDRO;
    }

    /**
     * 订单转化
     *
     * @param esOrderWork
     * @return
     */
    protected OrderDRO getOrderDRO(EsOrderWork esOrderWork) {
        OrderDRO orderDRO = BeanMapper.map(esOrderWork, OrderDRO.class);

        orderDRO.setPlat(esOrderWork.getPlat());
        orderDRO.setPlatWork(esOrderWork.getPlatWork());
        orderDRO.setOrderId(esOrderWork.getOrderId());
        orderDRO.setWorkId(esOrderWork.getId());
        orderDRO.setType(esOrderWork.getType());
        orderDRO.setReworkId(esOrderWork.getReworkId());
        orderDRO.setDutyTime(esOrderWork.getDutyTime());
        orderDRO.setProvinceId(esOrderWork.getProvinceId());
        orderDRO.setProvinceName(esOrderWork.getProvinceName());
        orderDRO.setCountryId(esOrderWork.getCountyId());
        orderDRO.setCountryName(esOrderWork.getCountyName());
        orderDRO.setStreet(esOrderWork.getContact().getStreet());
        orderDRO.setRemark(esOrderWork.getRemark());
        orderDRO.setOrgOneId(esOrderWork.getOrgOneId());
        orderDRO.setOrgTwoId(esOrderWork.getOrgTwoId());
        orderDRO.setOrgThreeId(esOrderWork.getOrgThreeId());
        orderDRO.setOrgFourId(esOrderWork.getOrgFourId());

        if (StringUtils.isNotBlank(esOrderWork.getContact().getLocation())) {
            String[] arr = esOrderWork.getContact().getLocation().split(",");
            orderDRO.setLatitude(Double.valueOf(arr[0]));
            orderDRO.setLongitude(Double.valueOf(arr[1]));
        }

        orderDRO.setAddress(esOrderWork.getContact().getAddress());
        orderDRO.setCityId(esOrderWork.getCityId());
        orderDRO.setCityName(esOrderWork.getCityName());
        orderDRO.setCategOneId(esOrderWork.getCategOneId());
        orderDRO.setCategId(esOrderWork.getCategTwoId());
        orderDRO.setShowCategId(esOrderWork.getShowCategTwoId());
        orderDRO.setShowCategName(esOrderWork.getShowCategTwoName());
        orderDRO.setShowCategOneId(esOrderWork.getShowCategOneId());
        orderDRO.setShowCategOneName(esOrderWork.getShowCategOneName());

        orderDRO.setChannelOneId(esOrderWork.getChannelOneId());
        orderDRO.setChannelTwoId(esOrderWork.getChannelTwoId());
        orderDRO.setChannelId(esOrderWork.getChannelId());
        orderDRO.setChannelName(esOrderWork.getChannelName());
        orderDRO.setCompantyId(esOrderWork.getCompanyId());
        orderDRO.setUserId(esOrderWork.getUserId());
        orderDRO.setServCategId(esOrderWork.getServCategId());
        orderDRO.setUserGender(esOrderWork.getContact().getGender());
        orderDRO.setUserName(esOrderWork.getContact().getUserName());
        orderDRO.setContactName(esOrderWork.getContact().getContactName());
        orderDRO.setUserPhone(esOrderWork.getContact().getPhone()[0]);
        orderDRO.setStatus(esOrderWork.getStatus());
        orderDRO.setResultStatus(esOrderWork.getResultStatus());
        if (esOrderWork.getContact().getPhone().length > 1) {
            orderDRO.setUserPhoneTwo(esOrderWork.getContact().getPhone()[1]);
        }
        List<EsOrderWorkOperate> operateList = esOrderWork.getOperateList();
        try {
            for (EsOrderWorkOperate operate : operateList) {
                Integer operateType = operate.getOperateType();
                Long operateId = operate.getOperatorId();
                if (Objects.equals(operateType, OrderConsts.ORDER_OP_TYPE_INPUT)) {
                    orderDRO.setReciverId(operateId);
                }
                if (Objects.equals(operateType, OrderConsts.ORDER_OP_TYPE_DISTRIBUTE)) {
                    orderDRO.setDistributeId(operateId);
                }
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        orderDRO.setMasterId(esOrderWork.getMasterId());
        orderDRO.setMasterName(esOrderWork.getMasterName());
        orderDRO.setMasterPhone(esOrderWork.getMasterPhone());
        orderDRO.setCategOneId(esOrderWork.getCategOneId());
        orderDRO.setCategOneName(esOrderWork.getCategOneName());
        orderDRO.setBizType(esOrderWork.getBizType());
        orderDRO.setBizModeSource(esOrderWork.getBizModeSource());
        orderDRO.setBizMode(esOrderWork.getBizMode());
        List<OrderProductDRO> productList = Lists.newArrayList();
        esOrderWork.getProductList().forEach(product -> {
            OrderProductDRO orderProductDRO = new OrderProductDRO(product.getProductId(), product.getProductName(), product.getNumber());
            orderProductDRO.setProductUnit(product.getProductUnit());
            orderProductDRO.setBrandId(product.getBrandId());
            orderProductDRO.setBrandName(product.getBrandName());
            orderProductDRO.setShowProductId(product.getShowProductId());
            orderProductDRO.setShowProductName(product.getShowProductName());
            orderProductDRO.setShowProductUnit(product.getShowProductUnit());
            productList.add(orderProductDRO);
        });
        orderDRO.setProductList(productList);

        orderDRO.setBizLine(esOrderWork.getBizLine());
        orderDRO.setServProductGroupId(esOrderWork.getServProductGroupId());
        orderDRO.setServProductGroupName(esOrderWork.getServProductGroupName());
        orderDRO.setPhone(esOrderWork.getContact().getPhone());
        orderDRO.setPhoneEnd4(esOrderWork.getContact().getPhoneEnd4());
        orderDRO.setCompanyId(esOrderWork.getCompanyId());
        orderDRO.setCompanyName(esOrderWork.getCompanyName());
        orderDRO.setManageCompanyId(esOrderWork.getManageCompanyId());
        orderDRO.setFinalPrice(Objects.equals(true, esOrderWork.getIsFinalPrice())
                && Objects.equals(esOrderWork.getServItemType(), OrderConsts.SERVICE_ITEM_TYPE_QUOTATION_THREE) ?
                GlobalConsts.YES : GlobalConsts.NO);

        return orderDRO;
    }

    protected SimpleOrderDRO getSimpleOrderDRO(EsOrderWork esOrderWork) {
        SimpleOrderDRO orderDRO = new SimpleOrderDRO();
        orderDRO.setIsExistWarranty(esOrderWork.getHasWarrantyCode());
        orderDRO.setOrderId(esOrderWork.getOrderId());
        orderDRO.setWorkId(esOrderWork.getId());
        orderDRO.setPlat(esOrderWork.getPlatWork());
        orderDRO.setType(esOrderWork.getType());
        orderDRO.setDutyTime(esOrderWork.getDutyTime());
        orderDRO.setCompleteTime(esOrderWork.getCompleteTime());
        orderDRO.setWorkResultStatusName(esOrderWork.getResultStatusName());
        orderDRO.setWorkStatusName(esOrderWork.getStatusName());
        orderDRO.setChannelId(esOrderWork.getChannelId());
        orderDRO.setChannelName(esOrderWork.getChannelName());
        orderDRO.setTotalAmount(esOrderWork.getTotalAmount());
        orderDRO.setDiscountAmount(esOrderWork.getDiscountAmount());
        orderDRO.setPrepayAmount(esOrderWork.getPrepayAmount());
        orderDRO.setDiscountPrepayAmount(esOrderWork.getDiscountPrepayAmount());
        orderDRO.setPayStatus(esOrderWork.getPayStatus());
        orderDRO.setHasDelivery(esOrderWork.getHasDelivery());
        orderDRO.setHasWaitPart(esOrderWork.getHasWaitPart());
        orderDRO.setWaitCancel(esOrderWork.getWaitCancel());
        orderDRO.setProductsEmission(esOrderWork.getProductsEmission());
        int orderStatus = OrderStatusConsts.getOrderStatus(esOrderWork.getStatus(), esOrderWork.getResultStatus());
        orderDRO.setStatus(orderStatus);
        List<OrderProductDRO> productList = Lists.newArrayList();
        esOrderWork.getProductList().forEach(product -> {
            OrderProductDRO orderProductDRO = new OrderProductDRO(product.getProductId(), product.getProductName(), product.getNumber());
            orderProductDRO.setShowProductId(product.getShowProductId());
            orderProductDRO.setShowProductName(product.getShowProductName());
            orderProductDRO.setShowProductUnit(product.getShowProductUnit());
            orderProductDRO.setProductUnit(product.getProductUnit());
            orderProductDRO.setBrandId(product.getBrandId());
            orderProductDRO.setBrandName(product.getBrandName());
            productList.add(orderProductDRO);
        });
        orderDRO.setProductList(productList);
        orderDRO.setBizLine(esOrderWork.getBizLine());
        orderDRO.setBizType(esOrderWork.getBizType());
        return orderDRO;
    }

    public ResponseDTO<UpdateOrderDRO> findOrderUpdateDetail(Long orderId, Long workId) {
        Objects.requireNonNull(orderId);
        logger.info("[{}] 查询修改订单ID：{}", TAG, orderId);
        try {
            ZsNormalUpdateOrderVO zsNormalUpdateOrderVO = zsOrderWorkBService.findUpdateOrderWorkVO(orderId, orderId);
            UpdateOrderDRO updateOrderDRO = BeanMapper.map(zsNormalUpdateOrderVO, UpdateOrderDRO.class);
            //厂商单信息
            if (zsNormalUpdateOrderVO.getOrderFactory() != null) {
                OrderFactoryDRO orderFactoryDRO = updateOrderDRO.getOrderFactory();
                ZsNormalUpdateOrderProductVO productVO = zsNormalUpdateOrderVO.getOrderProductList().get(0);
                orderFactoryDRO.setFaultIdList(productVO.getFaultIdList());
                orderFactoryDRO.setRemark(productVO.getRemark());
            }
            return ResponseDTO.success(updateOrderDRO, "OK");
        } catch (Exception ex) {
            ex.printStackTrace();
            logger.error("[{}] 查询修改订单详情错误：{}", TAG, ex);
            return ResponseDTO.fail(ex.getMessage());
        }
    }
}